package com.bamboo.eduservice.service.impl;

import com.bamboo.commonutils.ResponseEntity;
import com.bamboo.commonutils.ResultCode;
import com.bamboo.eduservice.entity.EduVideo;
import com.bamboo.eduservice.feign.VodFeignClient;
import com.bamboo.eduservice.mapper.EduVideoMapper;
import com.bamboo.eduservice.service.EduVideoService;
import com.bamboo.servicebase.exceptionhandler.BambooException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author jack.wu
 * @since 2020-07-05
 */
@Service
public class EduVideoServiceImpl extends ServiceImpl<EduVideoMapper, EduVideo> implements EduVideoService {

    @Resource
    private VodFeignClient vodFeignClient;

    @Override
    public void deleteVideoInfo(String id) {
        EduVideo video = getById(id);
        if (StringUtils.isEmpty(video.getVideoSourceId())){
            baseMapper.deleteById(id);
            return;
        }
        ResponseEntity result = vodFeignClient.deleteAlyVideo(video.getVideoSourceId());
        if (ResultCode.SUCCESS != result.getCode()) {
            throw new BambooException(20001, result.getMessage());
        }

    }
}
